
do "...\First.do"

clear
use "$work\Yder_9518_long.dta"


keep pnr mor_id far_id dad_ses mom_ses
duplicates drop 

********************************************************************************
* Mothers

preserve
keep mor_id
rename mor_id pnr
duplicates drop

merge 1:m pnr using "$raw\income.dta"
keep if _merge==3
drop _merge

bys pnr year: g N=_N
drop if N>1
drop N

drop pstill
keep if lonind!=.

sort pnr year
bys pnr: g n=_n

g help=1 if year==1980
bys pnr: egen max=max(help)
keep if (help==1 & max==1) | max==0

keep if (year==1980 & max==1 ) | (n==1 & max==0)
drop year

drop n help max

save "$work\mom_income1.dta",replace
restore



*FATHERS

preserve
keep far_id 
rename far_id pnr
duplicates drop
merge 1:m pnr using "$raw\income.dta"
keep if _merge==3
drop _merge


bys pnr year: g N=_N
drop if N>1
drop N

drop pstill
keep if lonind!=.

sort pnr year
bys pnr: g n=_n

g help=1 if year==1980
bys pnr: egen max=max(help)
keep if (help==1 & max==1) | max==0

keep if (year==1980 & max==1 ) | (n==1 & max==0)
drop year

drop n help max


save "$work\dad_income1.dta",replace
restore



********************************************************************************
* MERGE
********************************************************************************
rename pnr pnr_pcp
rename mor_id pnr 

merge m:1 pnr using "$work\mom_income1.dta"
drop _merge

rename arledgr arledgr_mom
rename lonind lonind_mom


rename pnr mor_id
rename far_id pnr 


merge m:1 pnr using "$work\dad_income1.dta"
drop _merge

rename arledgr arledgr_dad
rename lonind lonind_dad

rename pnr far_id


tab mom_ses
sum arledgr_mom

ttest arledgr_mom, by(mom_ses)
ttest lonind_mom, by(mom_ses)

ttest arledgr_dad, by(dad_ses)
ttest lonind_dad, by(dad_ses)








